<!DOCTYPE html>
<html lang="en">
<!-- 任务分配页面 -->
<?php
// 判断是否正常访问
session_start();
if (!isset($_SESSION['ADMIN'])) {
    echo "<script>alert('非法访问！请先登录！');window.location.href='../../../index.html';</script>";
    die();
}
if(empty($_GET['action'])){
    echo "<script>alert('非法传参！');window.location.href='a-main.php';</script>";
    die();
}

include_once('php/conn.php');
if($_GET['action'] != 'do'){
    echo "<script>alert('传参错误！');window.location.href='a-main.php';</script>";
    die();
}else{
    $fix_id = $_GET['fix_id'];
    $sql_1 = "SELECT * FROM tb_repairer WHERE r_status != '0' ORDER BY r_id ASC";
    $result_1 = mysqli_query($conn_DB, $sql_1);
    if (!$result_1) {
        echo "<script>alert('获取维修员信息失败！');window.location.href='a-main.php';</script>";
        die();
    }

    $sql_2 = "SELECT * FROM tb_fixinfo_request, tb_fix_leave WHERE tb_fixinfo_request.fix_id = '".$fix_id."'";
    $result_2 = mysqli_query($conn_DB, $sql_2);
    if (!$result_2) {
        echo "<script>alert('获取报修信息失败！');window.location.href='a-main.php';</script>";
        die();
    }else{
        $row_2 = mysqli_fetch_object($result_2);
        if($row_2->leave_num == '1'){
            $leave = '一级故障';
        }
        if($row_2->leave_num == '2'){
            $leave = '二级故障';
        }
        if($row_2->leave_num == '3'){
            $leave = '三级故障';
        }
    }
}
?>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="icon" href="../img/ICO.png">
    <title>校园报修系统 · 管理员</title>
    <link rel="stylesheet" href="../layui-v2.9.18/layui/css/layui.css">
    <link rel="stylesheet" href="../bootstrap-5.3.3-dist/bootstrap.min.css">
    <link rel="stylesheet" href="css/a-public.css">
    <link rel="stylesheet" href="css/a-allocated-tasks.css">
    <script src='js/a-allocated-tasks.js'></script>
</head>

<body>
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header">
            <div class="layui-logo layui-hide-xs layui-bg-black">
                <img src="../img/logo-0.png" height="100%">
            </div>
            <!-- 头部区域（可配合layui 已有的水平导航） -->
            <ul class="layui-nav layui-layout-left">
                <b class="layui-nav-item layui-show-xs-inline-block">
                    <i class="layui-icon layui-icon-date"></i> 日期：<span id="nowTime"></span> |
                    <i class="layui-icon layui-icon-time"></i> 时间：<span id="timeDisplay"></span>
                </b>
            </ul>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                    <a href="javascript:;">
                        <i class="layui-icon layui-icon-friends"> 登录管理员：</i>
                        <?php echo $_SESSION['ADMIN']['a_name'];?>
                        <span> | </span><span id="welcome"></span>
                    </a>
                </li>
                <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                    <a href="php/logout.php">
                        <i class="layui-icon layui-icon-return" title="退出登录"></i>
                    </a>
                </li>
            </ul>
        </div>
        <div class="layui-side layui-bg-black">
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree" lay-filter="test">
                    <li class="layui-nav-item">
                        <a href="javascript:;">系统面板</a>
                        <dl class="layui-nav-child">
                            <dd><a href="a-main.php">信息统计面板</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item layui-nav-itemed">
                        <a class="" href="javascript:;">报修任务处理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="a-tasks-pending.php">待处理任务</a></dd>
                            <dd><a href="a-tasks-ongoing.php">进行中任务</a></dd>
                            <dd><a href="a-tasks-history.php">历史任务查询</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">维修人员管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="a-repairer.php">人员信息总览</a></dd>
                            <dd><a href="a-repairer-add.php">人员信息添加</a></dd>
                            <dd><a href="a-repairer-change.php">人员信息修改</a></dd>
                            <dd><a href="a-repairer-del.php">维修账号停启用</a></dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">报修类型管理</a>
                        <dl class="layui-nav-child">
                            <dd><a href="a-type.php">报修类型总览</a></dd>
                            <dd><a href="a-type-change.php">修改报修类型</a></dd>
                            <dd><a href="a-type-add.php">添加报修类型</a></dd>
                        </dl>
                    </li>
                </ul>
            </div>
        </div>
        <div class="layui-body">
            <!-- 内容主体区域 -->
            <div style="padding: 15px;">
                <blockquote class="layui-elem-quote layui-text">
                    对 <?php echo $fix_id;?> 报修单进行任务分配
                </blockquote>
                <div class="layui-card layui-panel">
                    <div class="layui-card-body">
                        <div class="form-div">
                            <form class="row g-3" method="post" action="php/deal-tasks.php">
                                <input type="hidden" name="action" value="allocated">
                                <div class="col-md-5">
                                    <label for="fix_id" class="form-label">报修单号</label>
                                    <input type="text" class="form-control" id="fix_id" name="fix_id" value="<?php echo $row_2->fix_id;?>" readonly>
                                </div>
                                <div class="col-md-4">
                                    <label for="fix_sendtime" class="form-label">报修时间</label>
                                    <input type="text" class="form-control" id="fix_sendtime" value="<?php echo $row_2->fix_sendtime;?>" readonly>
                                </div>
                                <div class="col-md-3">
                                    <label for="fix_name" class="form-label">报修人</label>
                                    <input type="text" class="form-control" id="fix_name" value="<?php echo $row_2->fix_name;?>" readonly>
                                </div>
                                <div class="col-md-4">
                                    <label for="fix_type" class="form-label">故障类型</label>
                                    <input type="text" class="form-control" id="fix_type" value="<?php echo $row_2->fix_type;?>" readonly>
                                </div>
                                <div class="col-md-4">
                                    <label for="fix_leave" class="form-label">故障等级</label>
                                    <input type="text" class="form-control" id="fix_leave" value="<?php echo $leave;?>" readonly>
                                </div>
                                <div class="col-md-4">
                                    <label for="fix_area" class="form-label">故障区域</label>
                                    <input type="text" class="form-control" id="fix_area" value="<?php echo $row_2->fix_area;?>" readonly>
                                </div>
                                <div class="col-md-3">
                                    <label for="fix_reason" class="form-label">故障原因</label>
                                    <input type="text" class="form-control" id="fix_reason" value="<?php echo $row_2->fix_reason;?>" readonly>
                                </div>
                                <div class="col-md-9">
                                    <label for="fix_depicted" class="form-label">故障描述</label>
                                    <input type="text" class="form-control" id="fix_depicted" value="<?php echo $row_2->fix_depicted;?>" readonly>
                                </div>
                                <p>故障图</p>
                                <br>
                                <div class="img-div">
                                    <img src="../img/user_upload/<?php echo $row_2->fix_img;?>" alt="QAQ图片不见啦">
                                </div>
                                <div class="col-md-5">
                                    <label for="fix_repairer" class="form-label">可指派维修人员</label>
                                    <select id="fix_repairer" class="form-select select-style" id="fix_repairer" name="fix_repairer">
                                        <option value="none" disabled selected>---请选择维修人员---</option>
                                        <?php
                                            while ($row_1 = mysqli_fetch_object($result_1)) {
                                                echo "<option value='".$row_1->r_id."'>".$row_1->r_name."</option>";
                                            }
                                        ?>
                                    </select>
                                </div>
                                <div class="col-12 btn-style">
                                    <button type="submit" class="btn btn-primary" onclick="return checkOptions()">确认分发任务</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-footer">
            <!-- 底部固定区域 -->
            校园报修系统© 2025®
        </div>
    </div>
    <script src="../layui-v2.9.18/layui/layui.js" charset="utf-8"></script>
    <script src="js/getDatetime.js"></script>
</body>

</html>